import type { App } from "vue";
import {
  createRouter,
  createWebHashHistory,
  createWebHistory,
  type RouteRecordRaw,
} from "vue-router";

export const Layout = () => import("@/layouts/index.vue");

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/redirect",
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },

  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/map/:id?",
    name: "map",
    meta: { hidden: true },
    component: () => import("@/views/locusmap/index1.vue"),
  },
  {
    path: "/map1/:id?",
    name: "map1",
    meta: { hidden: true },
    component: () => import("@/views/locusmap/index.vue"),
  },
  {
    path: "/",
    name: "/",
    component: Layout,
    redirect: "/dashboard",
    meta: { hidden: true },
    children: [
      {
        path: "dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
        // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        name: "Dashboard",
        meta: {
          title: "dashboard",
          icon: "homepage",
          hidden: true,
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "401",
        component: () => import("@/views/error/401.vue"),
        meta: { hidden: true },
      },
      {
        path: "404",
        component: () => import("@/views/error/404.vue"),
        meta: { hidden: true },
      },
      {
        path: "profile",
        name: "Profile",
        component: () => import("@/views/profile/index.vue"),
        meta: { title: "个人中心", icon: "user", hidden: true },
      },
      {
        path: "my-notice",
        name: "MyNotice",
        component: () => import("@/views/system/notice/components/MyNotice.vue"),
        meta: { title: "我的通知", icon: "user", hidden: true },
      },
    ],
  },
  // {
  //   path: "/multi-level",
  //   component: "Layout",
  //   name: "/multiLevel",
  //   meta: {
  //     title: "多级菜单",
  //     icon: "cascader",
  //     hidden: false,
  //     alwaysShow: true,
  //     params: null,
  //   },
  //   children: [
  //     {
  //       path: "multi-level1",
  //       component: "demo/multi-level/level1",
  //       name: "MultiLevel1",
  //       meta: {
  //         title: "菜单一级",
  //         icon: "",
  //         hidden: false,
  //         alwaysShow: true,
  //         params: null,
  //       },
  //       children: [
  //         {
  //           path: "multi-level2",
  //           component: "demo/multi-level/children/level2",
  //           name: "MultiLevel2",
  //           meta: {
  //             title: "菜单二级",
  //             icon: "",
  //             hidden: false,
  //             alwaysShow: false,
  //             params: null,
  //           },
  //           children: [
  //             {
  //               path: "multi-level3-1",
  //               component: "demo/multi-level/children/children/level3-1",
  //               name: "MultiLevel31",
  //               meta: {
  //                 title: "菜单三级-1",
  //                 icon: "",
  //                 hidden: false,
  //                 keepAlive: true,
  //                 alwaysShow: false,
  //                 params: null,
  //               },
  //             },
  //             {
  //               path: "multi-level3-2",
  //               component: "demo/multi-level/children/children/level3-2",
  //               name: "MultiLevel32",
  //               meta: {
  //                 title: "菜单三级-2",
  //                 icon: "",
  //                 hidden: false,
  //                 keepAlive: true,
  //                 alwaysShow: false,
  //                 params: null,
  //               },
  //             },
  //           ],
  //         },
  //       ],
  //     },
  //   ],
  // },
  // {
  //   path: "/system",
  //   name: "/system",
  //   component: Layout,
  //   redirect: "/system/user",
  //   meta: {
  //     title: "系统管理",
  //     icon: "system",
  //     hidden: true,
  //   },
  //   children: [
  //     // {
  //     //   path: "user",
  //     //   component: () => import("@/views/system/user/index.vue"),
  //     //   name: "User",
  //     //   meta: {
  //     //     title: "用户管理",
  //     //     icon: "el-icon-User",
  //     //     affix: true,
  //     //   },
  //     // },
  //     // {
  //     //   path: "role",
  //     //   component: () => import("@/views/system/role/index.vue"),
  //     //   name: "Role",
  //     //   meta: {
  //     //     title: "角色管理",
  //     //     icon: "el-icon-User",
  //     //     affix: true,
  //     //   },
  //     // },
  //     {
  //       path: "menu",
  //       component: () => import("@/views/system/menu/index.vue"),
  //       name: "SysMenu",
  //       meta: {
  //         title: "菜单管理",
  //         icon: "menu",
  //         hidden: false,
  //         keepAlive: true,
  //       },
  //     },
  //   ],
  // },
];

/**
 * 创建路由
 */
const router = createRouter({
  // history: createWebHashHistory(),
  history: createWebHistory(),

  routes: constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

// 全局注册 router
export function setupRouter(app: App<Element>) {
  app.use(router);
}

export default router;
